{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "class Student:\n",
    "\n",
    "    company = \"Dalian\"\n",
    "    __count = 0\n",
    "\n",
    "    def __init__(self, name, sco) -> None:\n",
    "        self.name = name\n",
    "        self.__sco = sco\n",
    "        Student.__count += 1\n",
    "\n",
    "    def say_sco(self):\n",
    "        print(self.__sco)\n",
    "        print(Student.company)\n",
    "        print(Student.__count)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "zhangsan = Student(\"Zhang san\", 80)\n",
    "zhangsan._Student__count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import math\n",
    "help(math)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "import ex4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['/home/congyu/python-project/learn-py3-more/learnpy3more', '/home/congyu/anaconda3/lib/python311.zip', '/home/congyu/anaconda3/lib/python3.11', '/home/congyu/anaconda3/lib/python3.11/lib-dynload', '', '/home/congyu/.local/lib/python3.11/site-packages', '/home/congyu/anaconda3/lib/python3.11/site-packages']\n"
     ]
    }
   ],
   "source": [
    "import sys\n",
    "print(sys.path)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'This module provides access to the mathematical functions\\ndefined by the C standard.'"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import math\n",
    "math.__doc__\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "import ex4\n",
    "ex4.__doc__\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import aa01"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[tool.poetry]\n",
      "name = \"demo\"\n",
      "version = \"0.1.0\"\n",
      "description = \"\"\n",
      "authors = [\"张从瑜 <congyu99@163.com>\"]\n",
      "readme = \"README.md\"\n",
      "\n",
      "[tool.poetry.dependencies]\n",
      "python = \"^3.11\"\n",
      "\n",
      "\n",
      "[build-system]\n",
      "requires = [\"poetry-core\"]\n",
      "build-backend = \"poetry.core.masonry.api\"\n",
      "\n"
     ]
    }
   ],
   "source": [
    "with open(\"/home/congyu/python-project/demo/pyproject.toml\", \"r\", encoding=\"utf-8\") as f:\n",
    "    print(f.read())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['aliases', 'ascii', 'codecs', 'gb18030', 'gbk', 'idna', 'latin_1', 'sys', 'utf_8']\n"
     ]
    }
   ],
   "source": [
    "import encodings\n",
    "\n",
    "# 获取encodings包中的所有模块名称，这些通常对应于不同的编码\n",
    "encodings_list = [\n",
    "    name\n",
    "    for name in encodings.__dict__\n",
    "    if isinstance(encodings.__dict__[name], type(encodings.ascii))\n",
    "]\n",
    "print(sorted(encodings_list))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'__name__': 'encodings',\n",
       " '__doc__': ' Standard \"encodings\" Package\\n\\n    Standard Python encoding modules are stored in this package\\n    directory.\\n\\n    Codec modules must have names corresponding to normalized encoding\\n    names as defined in the normalize_encoding() function below, e.g.\\n    \\'utf-8\\' must be implemented by the module \\'utf_8.py\\'.\\n\\n    Each codec module must export the following interface:\\n\\n    * getregentry() -> codecs.CodecInfo object\\n    The getregentry() API must return a CodecInfo object with encoder, decoder,\\n    incrementalencoder, incrementaldecoder, streamwriter and streamreader\\n    attributes which adhere to the Python Codec Interface Standard.\\n\\n    In addition, a module may optionally also define the following\\n    APIs which are then used by the package\\'s codec search function:\\n\\n    * getaliases() -> sequence of encoding name strings to use as aliases\\n\\n    Alias names returned by getaliases() must be normalized encoding\\n    names as defined by normalize_encoding().\\n\\nWritten by Marc-Andre Lemburg (mal@lemburg.com).\\n\\n(c) Copyright CNRI, All Rights Reserved. NO WARRANTY.\\n\\n',\n",
       " '__package__': 'encodings',\n",
       " '__loader__': <_frozen_importlib_external.SourceFileLoader at 0x7f8037fd9a50>,\n",
       " '__spec__': ModuleSpec(name='encodings', loader=<_frozen_importlib_external.SourceFileLoader object at 0x7f8037fd9a50>, origin='/home/congyu/anaconda3/lib/python3.11/encodings/__init__.py', submodule_search_locations=['/home/congyu/anaconda3/lib/python3.11/encodings']),\n",
       " '__path__': ['/home/congyu/anaconda3/lib/python3.11/encodings'],\n",
       " '__file__': '/home/congyu/anaconda3/lib/python3.11/encodings/__init__.py',\n",
       " '__cached__': '/home/congyu/anaconda3/lib/python3.11/encodings/__pycache__/__init__.cpython-311.pyc',\n",
       " '__builtins__': {'__name__': 'builtins',\n",
       "  '__doc__': \"Built-in functions, types, exceptions, and other objects.\\n\\nThis module provides direct access to all 'built-in'\\nidentifiers of Python; for example, builtins.len is\\nthe full name for the built-in function len().\\n\\nThis module is not normally accessed explicitly by most\\napplications, but can be useful in modules that provide\\nobjects with the same name as a built-in value, but in\\nwhich the built-in of that name is also needed.\",\n",
       "  '__package__': '',\n",
       "  '__loader__': _frozen_importlib.BuiltinImporter,\n",
       "  '__spec__': ModuleSpec(name='builtins', loader=<class '_frozen_importlib.BuiltinImporter'>, origin='built-in'),\n",
       "  '__build_class__': <function __build_class__>,\n",
       "  '__import__': <function __import__(name, globals=None, locals=None, fromlist=(), level=0)>,\n",
       "  'abs': <function abs(x, /)>,\n",
       "  'all': <function all(iterable, /)>,\n",
       "  'any': <function any(iterable, /)>,\n",
       "  'ascii': <function ascii(obj, /)>,\n",
       "  'bin': <function bin(number, /)>,\n",
       "  'breakpoint': <function breakpoint>,\n",
       "  'callable': <function callable(obj, /)>,\n",
       "  'chr': <function chr(i, /)>,\n",
       "  'compile': <function compile(source, filename, mode, flags=0, dont_inherit=False, optimize=-1, *, _feature_version=-1)>,\n",
       "  'delattr': <function delattr(obj, name, /)>,\n",
       "  'dir': <function dir>,\n",
       "  'divmod': <function divmod(x, y, /)>,\n",
       "  'eval': <function eval(source, globals=None, locals=None, /)>,\n",
       "  'exec': <function exec(source, globals=None, locals=None, /, *, closure=None)>,\n",
       "  'format': <function format(value, format_spec='', /)>,\n",
       "  'getattr': <function getattr>,\n",
       "  'globals': <function globals()>,\n",
       "  'hasattr': <function hasattr(obj, name, /)>,\n",
       "  'hash': <function hash(obj, /)>,\n",
       "  'hex': <function hex(number, /)>,\n",
       "  'id': <function id(obj, /)>,\n",
       "  'input': <bound method Kernel.raw_input of <ipykernel.ipkernel.IPythonKernel object at 0x7f803502b150>>,\n",
       "  'isinstance': <function isinstance(obj, class_or_tuple, /)>,\n",
       "  'issubclass': <function issubclass(cls, class_or_tuple, /)>,\n",
       "  'iter': <function iter>,\n",
       "  'aiter': <function aiter(async_iterable, /)>,\n",
       "  'len': <function len(obj, /)>,\n",
       "  'locals': <function locals()>,\n",
       "  'max': <function max>,\n",
       "  'min': <function min>,\n",
       "  'next': <function next>,\n",
       "  'anext': <function anext>,\n",
       "  'oct': <function oct(number, /)>,\n",
       "  'ord': <function ord(c, /)>,\n",
       "  'pow': <function pow(base, exp, mod=None)>,\n",
       "  'print': <function print(*args, sep=' ', end='\\n', file=None, flush=False)>,\n",
       "  'repr': <function repr(obj, /)>,\n",
       "  'round': <function round(number, ndigits=None)>,\n",
       "  'setattr': <function setattr(obj, name, value, /)>,\n",
       "  'sorted': <function sorted(iterable, /, *, key=None, reverse=False)>,\n",
       "  'sum': <function sum(iterable, /, start=0)>,\n",
       "  'vars': <function vars>,\n",
       "  'None': None,\n",
       "  'Ellipsis': Ellipsis,\n",
       "  'NotImplemented': NotImplemented,\n",
       "  'False': False,\n",
       "  'True': True,\n",
       "  'bool': bool,\n",
       "  'memoryview': memoryview,\n",
       "  'bytearray': bytearray,\n",
       "  'bytes': bytes,\n",
       "  'classmethod': classmethod,\n",
       "  'complex': complex,\n",
       "  'dict': dict,\n",
       "  'enumerate': enumerate,\n",
       "  'filter': filter,\n",
       "  'float': float,\n",
       "  'frozenset': frozenset,\n",
       "  'property': property,\n",
       "  'int': int,\n",
       "  'list': list,\n",
       "  'map': map,\n",
       "  'object': object,\n",
       "  'range': range,\n",
       "  'reversed': reversed,\n",
       "  'set': set,\n",
       "  'slice': slice,\n",
       "  'staticmethod': staticmethod,\n",
       "  'str': str,\n",
       "  'super': super,\n",
       "  'tuple': tuple,\n",
       "  'type': type,\n",
       "  'zip': zip,\n",
       "  '__debug__': True,\n",
       "  'BaseException': BaseException,\n",
       "  'BaseExceptionGroup': BaseExceptionGroup,\n",
       "  'Exception': Exception,\n",
       "  'GeneratorExit': GeneratorExit,\n",
       "  'KeyboardInterrupt': KeyboardInterrupt,\n",
       "  'SystemExit': SystemExit,\n",
       "  'ArithmeticError': ArithmeticError,\n",
       "  'AssertionError': AssertionError,\n",
       "  'AttributeError': AttributeError,\n",
       "  'BufferError': BufferError,\n",
       "  'EOFError': EOFError,\n",
       "  'ImportError': ImportError,\n",
       "  'LookupError': LookupError,\n",
       "  'MemoryError': MemoryError,\n",
       "  'NameError': NameError,\n",
       "  'OSError': OSError,\n",
       "  'ReferenceError': ReferenceError,\n",
       "  'RuntimeError': RuntimeError,\n",
       "  'StopAsyncIteration': StopAsyncIteration,\n",
       "  'StopIteration': StopIteration,\n",
       "  'SyntaxError': SyntaxError,\n",
       "  'SystemError': SystemError,\n",
       "  'TypeError': TypeError,\n",
       "  'ValueError': ValueError,\n",
       "  'Warning': Warning,\n",
       "  'FloatingPointError': FloatingPointError,\n",
       "  'OverflowError': OverflowError,\n",
       "  'ZeroDivisionError': ZeroDivisionError,\n",
       "  'BytesWarning': BytesWarning,\n",
       "  'DeprecationWarning': DeprecationWarning,\n",
       "  'EncodingWarning': EncodingWarning,\n",
       "  'FutureWarning': FutureWarning,\n",
       "  'ImportWarning': ImportWarning,\n",
       "  'PendingDeprecationWarning': PendingDeprecationWarning,\n",
       "  'ResourceWarning': ResourceWarning,\n",
       "  'RuntimeWarning': RuntimeWarning,\n",
       "  'SyntaxWarning': SyntaxWarning,\n",
       "  'UnicodeWarning': UnicodeWarning,\n",
       "  'UserWarning': UserWarning,\n",
       "  'BlockingIOError': BlockingIOError,\n",
       "  'ChildProcessError': ChildProcessError,\n",
       "  'ConnectionError': ConnectionError,\n",
       "  'FileExistsError': FileExistsError,\n",
       "  'FileNotFoundError': FileNotFoundError,\n",
       "  'InterruptedError': InterruptedError,\n",
       "  'IsADirectoryError': IsADirectoryError,\n",
       "  'NotADirectoryError': NotADirectoryError,\n",
       "  'PermissionError': PermissionError,\n",
       "  'ProcessLookupError': ProcessLookupError,\n",
       "  'TimeoutError': TimeoutError,\n",
       "  'IndentationError': IndentationError,\n",
       "  'IndexError': IndexError,\n",
       "  'KeyError': KeyError,\n",
       "  'ModuleNotFoundError': ModuleNotFoundError,\n",
       "  'NotImplementedError': NotImplementedError,\n",
       "  'RecursionError': RecursionError,\n",
       "  'UnboundLocalError': UnboundLocalError,\n",
       "  'UnicodeError': UnicodeError,\n",
       "  'BrokenPipeError': BrokenPipeError,\n",
       "  'ConnectionAbortedError': ConnectionAbortedError,\n",
       "  'ConnectionRefusedError': ConnectionRefusedError,\n",
       "  'ConnectionResetError': ConnectionResetError,\n",
       "  'TabError': TabError,\n",
       "  'UnicodeDecodeError': UnicodeDecodeError,\n",
       "  'UnicodeEncodeError': UnicodeEncodeError,\n",
       "  'UnicodeTranslateError': UnicodeTranslateError,\n",
       "  'ExceptionGroup': ExceptionGroup,\n",
       "  'EnvironmentError': OSError,\n",
       "  'IOError': OSError,\n",
       "  'open': <function io.open(file, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=True, opener=None)>,\n",
       "  'copyright': Copyright (c) 2001-2023 Python Software Foundation.\n",
       "  All Rights Reserved.\n",
       "  \n",
       "  Copyright (c) 2000 BeOpen.com.\n",
       "  All Rights Reserved.\n",
       "  \n",
       "  Copyright (c) 1995-2001 Corporation for National Research Initiatives.\n",
       "  All Rights Reserved.\n",
       "  \n",
       "  Copyright (c) 1991-1995 Stichting Mathematisch Centrum, Amsterdam.\n",
       "  All Rights Reserved.,\n",
       "  'credits':     Thanks to CWI, CNRI, BeOpen.com, Zope Corporation and a cast of thousands\n",
       "      for supporting Python development.  See www.python.org for more information.,\n",
       "  'license': Type license() to see the full license text,\n",
       "  'help': Type help() for interactive help, or help(object) for help about object.,\n",
       "  'execfile': <function _pydev_bundle._pydev_execfile.execfile(file, glob=None, loc=None)>,\n",
       "  'runfile': <function _pydev_bundle.pydev_umd.runfile(filename, args=None, wdir=None, namespace=None)>,\n",
       "  '__IPYTHON__': True,\n",
       "  'display': <function IPython.core.display_functions.display(*objs, include=None, exclude=None, metadata=None, transient=None, display_id=None, raw=False, clear=False, **kwargs)>,\n",
       "  'get_ipython': <bound method InteractiveShell.get_ipython of <ipykernel.zmqshell.ZMQInteractiveShell object at 0x7f8030e34a90>>},\n",
       " 'codecs': <module 'codecs' (frozen)>,\n",
       " 'sys': <module 'sys' (built-in)>,\n",
       " 'aliases': <module 'encodings.aliases' from '/home/congyu/anaconda3/lib/python3.11/encodings/aliases.py'>,\n",
       " '_cache': {'utf_8': <codecs.CodecInfo object for encoding utf-8 at 0x7f8037f51fc0>,\n",
       "  'ascii': <codecs.CodecInfo object for encoding ascii at 0x7f803572f7c0>,\n",
       "  'utf8': <codecs.CodecInfo object for encoding utf-8 at 0x7f803572f820>,\n",
       "  'latin1': <codecs.CodecInfo object for encoding iso8859-1 at 0x7f8035784100>,\n",
       "  'latin_1': <codecs.CodecInfo object for encoding iso8859-1 at 0x7f8035784160>,\n",
       "  'idna': <codecs.CodecInfo object for encoding idna at 0x7f8035785d80>,\n",
       "  'gbk': <codecs.CodecInfo object for encoding gbk at 0x7f80305b9240>,\n",
       "  'gb18030': <codecs.CodecInfo object for encoding gb18030 at 0x7f80305b9180>},\n",
       " '_unknown': '--unknown--',\n",
       " '_import_tail': ['*'],\n",
       " '_aliases': {'646': 'ascii',\n",
       "  'ansi_x3.4_1968': 'ascii',\n",
       "  'ansi_x3_4_1968': 'ascii',\n",
       "  'ansi_x3.4_1986': 'ascii',\n",
       "  'cp367': 'ascii',\n",
       "  'csascii': 'ascii',\n",
       "  'ibm367': 'ascii',\n",
       "  'iso646_us': 'ascii',\n",
       "  'iso_646.irv_1991': 'ascii',\n",
       "  'iso_ir_6': 'ascii',\n",
       "  'us': 'ascii',\n",
       "  'us_ascii': 'ascii',\n",
       "  'base64': 'base64_codec',\n",
       "  'base_64': 'base64_codec',\n",
       "  'big5_tw': 'big5',\n",
       "  'csbig5': 'big5',\n",
       "  'big5_hkscs': 'big5hkscs',\n",
       "  'hkscs': 'big5hkscs',\n",
       "  'bz2': 'bz2_codec',\n",
       "  '037': 'cp037',\n",
       "  'csibm037': 'cp037',\n",
       "  'ebcdic_cp_ca': 'cp037',\n",
       "  'ebcdic_cp_nl': 'cp037',\n",
       "  'ebcdic_cp_us': 'cp037',\n",
       "  'ebcdic_cp_wt': 'cp037',\n",
       "  'ibm037': 'cp037',\n",
       "  'ibm039': 'cp037',\n",
       "  '1026': 'cp1026',\n",
       "  'csibm1026': 'cp1026',\n",
       "  'ibm1026': 'cp1026',\n",
       "  '1125': 'cp1125',\n",
       "  'ibm1125': 'cp1125',\n",
       "  'cp866u': 'cp1125',\n",
       "  'ruscii': 'cp1125',\n",
       "  '1140': 'cp1140',\n",
       "  'ibm1140': 'cp1140',\n",
       "  '1250': 'cp1250',\n",
       "  'windows_1250': 'cp1250',\n",
       "  '1251': 'cp1251',\n",
       "  'windows_1251': 'cp1251',\n",
       "  '1252': 'cp1252',\n",
       "  'windows_1252': 'cp1252',\n",
       "  '1253': 'cp1253',\n",
       "  'windows_1253': 'cp1253',\n",
       "  '1254': 'cp1254',\n",
       "  'windows_1254': 'cp1254',\n",
       "  '1255': 'cp1255',\n",
       "  'windows_1255': 'cp1255',\n",
       "  '1256': 'cp1256',\n",
       "  'windows_1256': 'cp1256',\n",
       "  '1257': 'cp1257',\n",
       "  'windows_1257': 'cp1257',\n",
       "  '1258': 'cp1258',\n",
       "  'windows_1258': 'cp1258',\n",
       "  '273': 'cp273',\n",
       "  'ibm273': 'cp273',\n",
       "  'csibm273': 'cp273',\n",
       "  '424': 'cp424',\n",
       "  'csibm424': 'cp424',\n",
       "  'ebcdic_cp_he': 'cp424',\n",
       "  'ibm424': 'cp424',\n",
       "  '437': 'cp437',\n",
       "  'cspc8codepage437': 'cp437',\n",
       "  'ibm437': 'cp437',\n",
       "  '500': 'cp500',\n",
       "  'csibm500': 'cp500',\n",
       "  'ebcdic_cp_be': 'cp500',\n",
       "  'ebcdic_cp_ch': 'cp500',\n",
       "  'ibm500': 'cp500',\n",
       "  '775': 'cp775',\n",
       "  'cspc775baltic': 'cp775',\n",
       "  'ibm775': 'cp775',\n",
       "  '850': 'cp850',\n",
       "  'cspc850multilingual': 'cp850',\n",
       "  'ibm850': 'cp850',\n",
       "  '852': 'cp852',\n",
       "  'cspcp852': 'cp852',\n",
       "  'ibm852': 'cp852',\n",
       "  '855': 'cp855',\n",
       "  'csibm855': 'cp855',\n",
       "  'ibm855': 'cp855',\n",
       "  '857': 'cp857',\n",
       "  'csibm857': 'cp857',\n",
       "  'ibm857': 'cp857',\n",
       "  '858': 'cp858',\n",
       "  'csibm858': 'cp858',\n",
       "  'ibm858': 'cp858',\n",
       "  '860': 'cp860',\n",
       "  'csibm860': 'cp860',\n",
       "  'ibm860': 'cp860',\n",
       "  '861': 'cp861',\n",
       "  'cp_is': 'cp861',\n",
       "  'csibm861': 'cp861',\n",
       "  'ibm861': 'cp861',\n",
       "  '862': 'cp862',\n",
       "  'cspc862latinhebrew': 'cp862',\n",
       "  'ibm862': 'cp862',\n",
       "  '863': 'cp863',\n",
       "  'csibm863': 'cp863',\n",
       "  'ibm863': 'cp863',\n",
       "  '864': 'cp864',\n",
       "  'csibm864': 'cp864',\n",
       "  'ibm864': 'cp864',\n",
       "  '865': 'cp865',\n",
       "  'csibm865': 'cp865',\n",
       "  'ibm865': 'cp865',\n",
       "  '866': 'cp866',\n",
       "  'csibm866': 'cp866',\n",
       "  'ibm866': 'cp866',\n",
       "  '869': 'cp869',\n",
       "  'cp_gr': 'cp869',\n",
       "  'csibm869': 'cp869',\n",
       "  'ibm869': 'cp869',\n",
       "  '932': 'cp932',\n",
       "  'ms932': 'cp932',\n",
       "  'mskanji': 'cp932',\n",
       "  'ms_kanji': 'cp932',\n",
       "  '949': 'cp949',\n",
       "  'ms949': 'cp949',\n",
       "  'uhc': 'cp949',\n",
       "  '950': 'cp950',\n",
       "  'ms950': 'cp950',\n",
       "  'jisx0213': 'euc_jis_2004',\n",
       "  'eucjis2004': 'euc_jis_2004',\n",
       "  'euc_jis2004': 'euc_jis_2004',\n",
       "  'eucjisx0213': 'euc_jisx0213',\n",
       "  'eucjp': 'euc_jp',\n",
       "  'ujis': 'euc_jp',\n",
       "  'u_jis': 'euc_jp',\n",
       "  'euckr': 'euc_kr',\n",
       "  'korean': 'euc_kr',\n",
       "  'ksc5601': 'euc_kr',\n",
       "  'ks_c_5601': 'euc_kr',\n",
       "  'ks_c_5601_1987': 'euc_kr',\n",
       "  'ksx1001': 'euc_kr',\n",
       "  'ks_x_1001': 'euc_kr',\n",
       "  'gb18030_2000': 'gb18030',\n",
       "  'chinese': 'gb2312',\n",
       "  'csiso58gb231280': 'gb2312',\n",
       "  'euc_cn': 'gb2312',\n",
       "  'euccn': 'gb2312',\n",
       "  'eucgb2312_cn': 'gb2312',\n",
       "  'gb2312_1980': 'gb2312',\n",
       "  'gb2312_80': 'gb2312',\n",
       "  'iso_ir_58': 'gb2312',\n",
       "  '936': 'gbk',\n",
       "  'cp936': 'gbk',\n",
       "  'ms936': 'gbk',\n",
       "  'hex': 'hex_codec',\n",
       "  'roman8': 'hp_roman8',\n",
       "  'r8': 'hp_roman8',\n",
       "  'csHPRoman8': 'hp_roman8',\n",
       "  'cp1051': 'hp_roman8',\n",
       "  'ibm1051': 'hp_roman8',\n",
       "  'hzgb': 'hz',\n",
       "  'hz_gb': 'hz',\n",
       "  'hz_gb_2312': 'hz',\n",
       "  'csiso2022jp': 'iso2022_jp',\n",
       "  'iso2022jp': 'iso2022_jp',\n",
       "  'iso_2022_jp': 'iso2022_jp',\n",
       "  'iso2022jp_1': 'iso2022_jp_1',\n",
       "  'iso_2022_jp_1': 'iso2022_jp_1',\n",
       "  'iso2022jp_2': 'iso2022_jp_2',\n",
       "  'iso_2022_jp_2': 'iso2022_jp_2',\n",
       "  'iso_2022_jp_2004': 'iso2022_jp_2004',\n",
       "  'iso2022jp_2004': 'iso2022_jp_2004',\n",
       "  'iso2022jp_3': 'iso2022_jp_3',\n",
       "  'iso_2022_jp_3': 'iso2022_jp_3',\n",
       "  'iso2022jp_ext': 'iso2022_jp_ext',\n",
       "  'iso_2022_jp_ext': 'iso2022_jp_ext',\n",
       "  'csiso2022kr': 'iso2022_kr',\n",
       "  'iso2022kr': 'iso2022_kr',\n",
       "  'iso_2022_kr': 'iso2022_kr',\n",
       "  'csisolatin6': 'iso8859_10',\n",
       "  'iso_8859_10': 'iso8859_10',\n",
       "  'iso_8859_10_1992': 'iso8859_10',\n",
       "  'iso_ir_157': 'iso8859_10',\n",
       "  'l6': 'iso8859_10',\n",
       "  'latin6': 'iso8859_10',\n",
       "  'thai': 'iso8859_11',\n",
       "  'iso_8859_11': 'iso8859_11',\n",
       "  'iso_8859_11_2001': 'iso8859_11',\n",
       "  'iso_8859_13': 'iso8859_13',\n",
       "  'l7': 'iso8859_13',\n",
       "  'latin7': 'iso8859_13',\n",
       "  'iso_8859_14': 'iso8859_14',\n",
       "  'iso_8859_14_1998': 'iso8859_14',\n",
       "  'iso_celtic': 'iso8859_14',\n",
       "  'iso_ir_199': 'iso8859_14',\n",
       "  'l8': 'iso8859_14',\n",
       "  'latin8': 'iso8859_14',\n",
       "  'iso_8859_15': 'iso8859_15',\n",
       "  'l9': 'iso8859_15',\n",
       "  'latin9': 'iso8859_15',\n",
       "  'iso_8859_16': 'iso8859_16',\n",
       "  'iso_8859_16_2001': 'iso8859_16',\n",
       "  'iso_ir_226': 'iso8859_16',\n",
       "  'l10': 'iso8859_16',\n",
       "  'latin10': 'iso8859_16',\n",
       "  'csisolatin2': 'iso8859_2',\n",
       "  'iso_8859_2': 'iso8859_2',\n",
       "  'iso_8859_2_1987': 'iso8859_2',\n",
       "  'iso_ir_101': 'iso8859_2',\n",
       "  'l2': 'iso8859_2',\n",
       "  'latin2': 'iso8859_2',\n",
       "  'csisolatin3': 'iso8859_3',\n",
       "  'iso_8859_3': 'iso8859_3',\n",
       "  'iso_8859_3_1988': 'iso8859_3',\n",
       "  'iso_ir_109': 'iso8859_3',\n",
       "  'l3': 'iso8859_3',\n",
       "  'latin3': 'iso8859_3',\n",
       "  'csisolatin4': 'iso8859_4',\n",
       "  'iso_8859_4': 'iso8859_4',\n",
       "  'iso_8859_4_1988': 'iso8859_4',\n",
       "  'iso_ir_110': 'iso8859_4',\n",
       "  'l4': 'iso8859_4',\n",
       "  'latin4': 'iso8859_4',\n",
       "  'csisolatincyrillic': 'iso8859_5',\n",
       "  'cyrillic': 'iso8859_5',\n",
       "  'iso_8859_5': 'iso8859_5',\n",
       "  'iso_8859_5_1988': 'iso8859_5',\n",
       "  'iso_ir_144': 'iso8859_5',\n",
       "  'arabic': 'iso8859_6',\n",
       "  'asmo_708': 'iso8859_6',\n",
       "  'csisolatinarabic': 'iso8859_6',\n",
       "  'ecma_114': 'iso8859_6',\n",
       "  'iso_8859_6': 'iso8859_6',\n",
       "  'iso_8859_6_1987': 'iso8859_6',\n",
       "  'iso_ir_127': 'iso8859_6',\n",
       "  'csisolatingreek': 'iso8859_7',\n",
       "  'ecma_118': 'iso8859_7',\n",
       "  'elot_928': 'iso8859_7',\n",
       "  'greek': 'iso8859_7',\n",
       "  'greek8': 'iso8859_7',\n",
       "  'iso_8859_7': 'iso8859_7',\n",
       "  'iso_8859_7_1987': 'iso8859_7',\n",
       "  'iso_ir_126': 'iso8859_7',\n",
       "  'csisolatinhebrew': 'iso8859_8',\n",
       "  'hebrew': 'iso8859_8',\n",
       "  'iso_8859_8': 'iso8859_8',\n",
       "  'iso_8859_8_1988': 'iso8859_8',\n",
       "  'iso_ir_138': 'iso8859_8',\n",
       "  'csisolatin5': 'iso8859_9',\n",
       "  'iso_8859_9': 'iso8859_9',\n",
       "  'iso_8859_9_1989': 'iso8859_9',\n",
       "  'iso_ir_148': 'iso8859_9',\n",
       "  'l5': 'iso8859_9',\n",
       "  'latin5': 'iso8859_9',\n",
       "  'cp1361': 'johab',\n",
       "  'ms1361': 'johab',\n",
       "  'cskoi8r': 'koi8_r',\n",
       "  'kz_1048': 'kz1048',\n",
       "  'rk1048': 'kz1048',\n",
       "  'strk1048_2002': 'kz1048',\n",
       "  '8859': 'latin_1',\n",
       "  'cp819': 'latin_1',\n",
       "  'csisolatin1': 'latin_1',\n",
       "  'ibm819': 'latin_1',\n",
       "  'iso8859': 'latin_1',\n",
       "  'iso8859_1': 'latin_1',\n",
       "  'iso_8859_1': 'latin_1',\n",
       "  'iso_8859_1_1987': 'latin_1',\n",
       "  'iso_ir_100': 'latin_1',\n",
       "  'l1': 'latin_1',\n",
       "  'latin': 'latin_1',\n",
       "  'latin1': 'latin_1',\n",
       "  'maccyrillic': 'mac_cyrillic',\n",
       "  'macgreek': 'mac_greek',\n",
       "  'maciceland': 'mac_iceland',\n",
       "  'maccentraleurope': 'mac_latin2',\n",
       "  'mac_centeuro': 'mac_latin2',\n",
       "  'maclatin2': 'mac_latin2',\n",
       "  'macintosh': 'mac_roman',\n",
       "  'macroman': 'mac_roman',\n",
       "  'macturkish': 'mac_turkish',\n",
       "  'ansi': 'mbcs',\n",
       "  'dbcs': 'mbcs',\n",
       "  'csptcp154': 'ptcp154',\n",
       "  'pt154': 'ptcp154',\n",
       "  'cp154': 'ptcp154',\n",
       "  'cyrillic_asian': 'ptcp154',\n",
       "  'quopri': 'quopri_codec',\n",
       "  'quoted_printable': 'quopri_codec',\n",
       "  'quotedprintable': 'quopri_codec',\n",
       "  'rot13': 'rot_13',\n",
       "  'csshiftjis': 'shift_jis',\n",
       "  'shiftjis': 'shift_jis',\n",
       "  'sjis': 'shift_jis',\n",
       "  's_jis': 'shift_jis',\n",
       "  'shiftjis2004': 'shift_jis_2004',\n",
       "  'sjis_2004': 'shift_jis_2004',\n",
       "  's_jis_2004': 'shift_jis_2004',\n",
       "  'shiftjisx0213': 'shift_jisx0213',\n",
       "  'sjisx0213': 'shift_jisx0213',\n",
       "  's_jisx0213': 'shift_jisx0213',\n",
       "  'tis620': 'tis_620',\n",
       "  'tis_620_0': 'tis_620',\n",
       "  'tis_620_2529_0': 'tis_620',\n",
       "  'tis_620_2529_1': 'tis_620',\n",
       "  'iso_ir_166': 'tis_620',\n",
       "  'u16': 'utf_16',\n",
       "  'utf16': 'utf_16',\n",
       "  'unicodebigunmarked': 'utf_16_be',\n",
       "  'utf_16be': 'utf_16_be',\n",
       "  'unicodelittleunmarked': 'utf_16_le',\n",
       "  'utf_16le': 'utf_16_le',\n",
       "  'u32': 'utf_32',\n",
       "  'utf32': 'utf_32',\n",
       "  'utf_32be': 'utf_32_be',\n",
       "  'utf_32le': 'utf_32_le',\n",
       "  'u7': 'utf_7',\n",
       "  'utf7': 'utf_7',\n",
       "  'unicode_1_1_utf_7': 'utf_7',\n",
       "  'u8': 'utf_8',\n",
       "  'utf': 'utf_8',\n",
       "  'utf8': 'utf_8',\n",
       "  'utf8_ucs2': 'utf_8',\n",
       "  'utf8_ucs4': 'utf_8',\n",
       "  'cp65001': 'utf_8',\n",
       "  'uu': 'uu_codec',\n",
       "  'zip': 'zlib_codec',\n",
       "  'zlib': 'zlib_codec',\n",
       "  'x_mac_japanese': 'shift_jis',\n",
       "  'x_mac_korean': 'euc_kr',\n",
       "  'x_mac_simp_chinese': 'gb2312',\n",
       "  'x_mac_trad_chinese': 'big5'},\n",
       " 'CodecRegistryError': encodings.CodecRegistryError,\n",
       " 'normalize_encoding': <function encodings.normalize_encoding(encoding)>,\n",
       " 'search_function': <function encodings.search_function(encoding)>,\n",
       " 'utf_8': <module 'encodings.utf_8' from '/home/congyu/anaconda3/lib/python3.11/encodings/utf_8.py'>,\n",
       " 'ascii': <module 'encodings.ascii' from '/home/congyu/anaconda3/lib/python3.11/encodings/ascii.py'>,\n",
       " 'latin_1': <module 'encodings.latin_1' from '/home/congyu/anaconda3/lib/python3.11/encodings/latin_1.py'>,\n",
       " 'idna': <module 'encodings.idna' from '/home/congyu/anaconda3/lib/python3.11/encodings/idna.py'>,\n",
       " 'gbk': <module 'encodings.gbk' from '/home/congyu/anaconda3/lib/python3.11/encodings/gbk.py'>,\n",
       " 'gb18030': <module 'encodings.gb18030' from '/home/congyu/anaconda3/lib/python3.11/encodings/gb18030.py'>}"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "encodings.__dict__"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "系统默认编码方式: utf-8\n"
     ]
    }
   ],
   "source": [
    "import sys\n",
    "\n",
    "# 获取系统默认的编码方式\n",
    "default_encoding = sys.getdefaultencoding()\n",
    "\n",
    "print(\"系统默认编码方式:\", default_encoding)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "系统文件系统编码: UTF-8\n"
     ]
    }
   ],
   "source": [
    "import locale\n",
    "\n",
    "# 获取系统文件系统编码\n",
    "filesystem_encoding = locale.getpreferredencoding()\n",
    "\n",
    "print(\"系统文件系统编码:\", filesystem_encoding)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "b'Hello, \\xe4\\xb8\\x96\\xe7\\x95\\x8c!'\n",
      "b'Hello, \\xca\\xc0\\xbd\\xe7!'\n"
     ]
    }
   ],
   "source": [
    "# 定义一个Unicode字符串\n",
    "text = \"Hello, 世界!\"\n",
    "\n",
    "# 使用UTF-8编码转换为字节序列\n",
    "encoded_text = text.encode(\"utf-8\")\n",
    "\n",
    "print(encoded_text)  # 输出: b'Hello, \\xe4\\xb8\\x96\\xe7\\x95\\x8c!'\n",
    "\n",
    "encoded_text = text.encode(\"gb18030\")\n",
    "\n",
    "print(encoded_text)  # 输出:b'Hello, \\xca\\xc0\\xbd\\xe7!'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "猜测的编码: Windows-1252\n",
      "置信度: 0.73\n",
      "Hello, ä¸–!\n",
      "猜测的编码: utf-8\n",
      "置信度: 0.7525\n",
      "Hello, 世界!\n",
      "猜测的编码: ISO-8859-9\n",
      "置信度: 0.20244315764211882\n",
      "Hello, Hello, ÊÀ½ç!\n"
     ]
    }
   ],
   "source": [
    "import chardet\n",
    "\n",
    "# 假设我们有一个未知编码的字节序列\n",
    "byte_data = [b\"Hello, \\xe4\\xb8\\x96!\", b\"Hello, \\xe4\\xb8\\x96\\xe7\\x95\\x8c!\", b\"Hello, Hello, \\xca\\xc0\\xbd\\xe7!\"]\n",
    "\n",
    "# 使用chardet.detect()函数来检测编码\n",
    "for data in byte_data:\n",
    "    detected = chardet.detect(data)\n",
    "\n",
    "    print(\"猜测的编码:\", detected[\"encoding\"])\n",
    "    print(\"置信度:\", detected[\"confidence\"])\n",
    "\n",
    "    encoded_text = data.decode(detected[\"encoding\"])\n",
    "    print(encoded_text)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hello, 世!\n"
     ]
    }
   ],
   "source": [
    "# 定义一个UTF-8编码的字节序列\n",
    "encoded_text = b\"Hello, \\xe4\\xb8\\x96!\"\n",
    "\n",
    "# 使用UTF-8解码转换回Unicode字符串\n",
    "decoded_text = encoded_text.decode(\"utf-8\")\n",
    "\n",
    "print(decoded_text)  # 输出: \"Hello, 世界!\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "猜测的编码: Windows-1252\n",
      "置信度: 0.73\n",
      "解码后的文本: Hello, ä¸–!\n"
     ]
    }
   ],
   "source": [
    "import chardet\n",
    "\n",
    "# 假设我们有一个未知编码的字节序列\n",
    "byte_data = b\"Hello, \\xe4\\xb8\\x96!\"\n",
    "\n",
    "# 使用chardet.detect()函数来检测编码\n",
    "detected = chardet.detect(byte_data)\n",
    "\n",
    "# 打印猜测的编码和置信度\n",
    "print(\"猜测的编码:\", detected[\"encoding\"])\n",
    "print(\"置信度:\", detected[\"confidence\"])\n",
    "\n",
    "# 尝试使用猜测的编码解码\n",
    "try:\n",
    "    decoded_text = byte_data.decode(detected[\"encoding\"])\n",
    "    print(\"解码后的文本:\", decoded_text)\n",
    "except UnicodeDecodeError as e:\n",
    "    print(\"解码失败，错误信息:\", e)\n",
    "\n",
    "    # 如果解码失败，你可以尝试其他的常见编码\n",
    "    # 例如，尝试使用'utf-8'或'latin-1'等\n",
    "    try:\n",
    "        decoded_text = byte_data.decode(\"utf-8\")\n",
    "        print(\"使用 UTF-8 解码后的文本:\", decoded_text)\n",
    "    except UnicodeDecodeError as e:\n",
    "        print(\"使用 UTF-8 解码也失败了，错误信息:\", e)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.1.undefined"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
